package com.hc.runConfig;

import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
//    private JLabel myScriptName;
    private LabeledComponent<TextFieldWithBrowseButton> myScriptName;
    private JPanel myPanel;
    private JTextField userName;
    private JLabel lUserName;
    private JPasswordField password;

    @Override
    protected void resetEditorFrom(@NotNull DemoRunConfiguration demoRunConfiguration) {
//        TextFieldWithBrowseButton component = myScriptName.getComponent();
//        if(component==null){
//            myScriptName.setComponent(component=new TextFieldWithBrowseButton());
//        }
//        component.setText(demoRunConfiguration.getScriptName());
        userName.setText(demoRunConfiguration.getUserName());
        password.setText(demoRunConfiguration.getPassword());
    }

    @Override
    protected void applyEditorTo(@NotNull DemoRunConfiguration demoRunConfiguration) throws ConfigurationException {

//        demoRunConfiguration.setScriptName(myScriptName.getComponent().getText());
        demoRunConfiguration.setUserName(userName.getText());
        demoRunConfiguration.setPassword(password.getText());
    }

    @NotNull
    @Override
    protected JComponent createEditor() {
        return myPanel;
    }

    private void createUIComponents() {
//        myScriptName = new LabeledComponent<>();
        userName=new JTextField();
        password=new JPasswordField();
    }

}
